//
//  NumberViewController.m
//  markmap
//
//  Created by 甘世清 on 2024/6/26.
//

#import "NumberViewController.h"
#import <FSTextView/FSTextView.h>
#import "CodeViewController.h"
@interface NumberViewController ()
@property (nonatomic , assign) BOOL isXieyi;
@property (nonatomic , strong) FSTextView * emailtextField;
@property (nonatomic , strong) SQCustomButton * rightBtn;
@end

@implementation NumberViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColor.blackColor;
}

- (void)SQ_UIViewForSelfView{
    
    UILabel * label = [[UILabel alloc]init];
    label.textColor = UIColor.whiteColor;
    label.font = FONT_SEMIBOLD(28);
    label.text =  SQNSLocalString(@"手机号注册/登录");
    [self.view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view).offset(35);
            make.top.equalTo(self.zx_navBar.mas_bottom).offset(20);
    }];
    
    UIImageView * bg = [[UIImageView alloc]init];
    bg.image = SQGetImage(@"logoTop");
    bg.contentMode = UIViewContentModeScaleAspectFill;
    [self.view addSubview:bg];
    [bg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.view).offset(240);
        make.width.mas_equalTo(SCREEN_WIDETH-140);
        make.height.mas_equalTo(135);
    }];
    UIView * bgView = [[UIView alloc]init];
    bgView.backgroundColor = SQColor(@"#414141");
    bgView.layer.cornerRadius = 25;
    bgView.layer.masksToBounds = YES;
    [self.view addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.view);
            make.height.mas_equalTo(50);
            make.width.mas_equalTo(SCREEN_WIDETH-70);
        make.top.equalTo(bg.mas_bottom).offset(30);
    }];
    UILabel * label86 = [[UILabel alloc]init];
    label86.text = @"+86";
    label86.font = FONT_MEDIUM(17);
    label86.textColor = UIColor.whiteColor;
    [bgView addSubview:label86];
    [label86 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(bgView).offset(16);
            make.centerY.equalTo(bgView);
    }];
    UIView * lineView = [[UIView alloc]init];
    lineView .backgroundColor = UIColor.whiteColor;
    [bgView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(1);
            make.centerY.equalTo(bgView);
            make.height.mas_equalTo(26);
            make.left.equalTo(bgView).offset(64);
    }];
    
    
    [bgView addSubview:self.emailtextField];
    [self.emailtextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(bgView).offset(7);
        make.left.equalTo(bgView).offset(100);
        make.height.mas_equalTo(50);
        make.right.equalTo(bgView.mas_right);
    }];
    
   
    WS(weakSelf);
    self.rightBtn = [[SQCustomButton alloc]initType:SQCustomButtonLeftImageType imageSize:CGSizeMake(0, 0) midmargin:0];
    
    self.rightBtn.text = SQNSLocalString(@"获取短信验证码");
    self.rightBtn.textColor = SQColor(@"#6B6B6B");
    self.rightBtn.font = FONT_MEDIUM(15);
    self.rightBtn.SQBackimageView.hidden = YES;
    self.rightBtn.SQBackimageView.contentMode = UIViewContentModeScaleAspectFill;
    self.rightBtn.clipsToBounds = YES;
    self.rightBtn.SQBackimageView.image = SQGetImage(@"按钮背景");
    self.rightBtn.backgroundColor = SQColor(@"#CECECE");
    self.rightBtn.layer.cornerRadius = 25;
    [self.view addSubview:self.rightBtn];
   
    [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.emailtextField.mas_bottom).offset(30);
        make.height.mas_equalTo(50);
        make.width.mas_equalTo(SCREEN_WIDETH-60);
        make.centerX.equalTo(self.view);
    }];
    [self.rightBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [weakSelf SQ_pgLogin];
    }];
    
    [self.emailtextField addTextDidChangeHandler:^(FSTextView *textView) {
        if (textView.formatText.length != 11) {
            weakSelf.rightBtn.SQBackimageView.hidden = YES;
            weakSelf.rightBtn.textColor = SQColor(@"#6B6B6B");

        } else {
            weakSelf.rightBtn.SQBackimageView.hidden = NO;
            weakSelf.rightBtn.textColor = UIColor.whiteColor;
        }
    }];
    
    YYLabel * label3 = [[YYLabel alloc]initWithFrame:CGRectMake(SCREEN_WIDETH/2.f-100, SCREEN_HEIGHT- FootHeight-40, 260, 40)];
    label3.textVerticalAlignment = YYTextVerticalAlignmentCenter;
    label3.textAlignment = NSTextAlignmentCenter;
    label3.numberOfLines = 0;
    [self.view addSubview:label3];
    NSDictionary *attributes = @{NSFontAttributeName:FONT_MEDIUM(12) , NSForegroundColorAttributeName: SQColor(@"#DBDBDB")};
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:SQNSLocalString(@"我已阅读并同意 《用户协议》、《隐私协议》") attributes:attributes];
   
    //设置高亮色和点击事件
    [text yy_setTextHighlightRange:[[text string] rangeOfString:SQNSLocalString(@"《用户协议》")] color:SQColor(@"#FFFFFF") backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        CommonWebVcView *vc= [[CommonWebVcView alloc]init];
        vc.urlStr =  YHXY;
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    NSRange range1=[[text string]rangeOfString:SQNSLocalString(@"《用户协议》")];
    YYTextDecoration* deco=[YYTextDecoration decorationWithStyle:(YYTextLineStyleSingle) width:[NSNumber numberWithInt:0] color:[UIColor whiteColor]];
    [text yy_setTextUnderline:deco range:range1];
    
    //设置高亮色和点击事件
    [text yy_setTextHighlightRange:[[text string] rangeOfString:SQNSLocalString(@"《隐私协议》")] color:SQColor(@"#FFFFFF") backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        CommonWebVcView *vc= [[CommonWebVcView alloc]init];
        vc.urlStr =  YSTK;
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    NSRange range2=[[text string]rangeOfString:SQNSLocalString(@"《隐私协议》") ];
    YYTextDecoration* deco2=[YYTextDecoration decorationWithStyle:(YYTextLineStyleSingle) width:[NSNumber numberWithInt:0] color:[UIColor whiteColor]];
    [text yy_setTextUnderline:deco2 range:range2];
    label3.attributedText = text;
    
    SQCustomButton * leftbtn = [[SQCustomButton alloc]initType:SQCustomButtonLeftImageType imageSize:CGSizeMake(15, 15) midmargin:6];
    leftbtn.image = SQGetImage(@"选择");
    [self.view addSubview:leftbtn];
    [leftbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(label3);
        make.height.mas_equalTo(40);
        make.right.equalTo(label3.mas_left);
        make.width.mas_equalTo(40);
    }];
    
    [leftbtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        weakSelf.isXieyi = !weakSelf.isXieyi;
        if (weakSelf.isXieyi) {
            button.image = SQGetImage(@"未选择");
        } else {
            button.image = SQGetImage(@"选择");
        }
    }];
}
-(void)SQ_pgLogin{
    if (self.emailtextField.formatText.length != 11) {
        return;
    }
    if (self.isXieyi) {
        [YJProgressHUD showMsgWithoutView:SQNSLocalString(@"请查看并勾选协议")];
        return;
    }
    if (![self.emailtextField.text isNotEmpty]) {
        [YJProgressHUD showMsgWithoutView:SQNSLocalString(@"请输入手机号")];
        return;
    }
   
    CodeViewController * vc = [[CodeViewController alloc]init];
    vc.phoneString = self.emailtextField.text;
    [self SQ_pushViewControllerFull:vc];
}
 

- (FSTextView *)emailtextField{
    if (!_emailtextField) {
        _emailtextField = [FSTextView textView];
        _emailtextField.placeholder = SQNSLocalString(@"请输入手机号");
        _emailtextField.placeholderColor = SQColor(@"#6B6B6B");
        _emailtextField.font = FONT_MEDIUM(17);
        _emailtextField.textColor = UIColor.whiteColor;
        _emailtextField.keyboardType = UIKeyboardTypeNumberPad;
        _emailtextField.maxLength = 11;
        _emailtextField.backgroundColor = UIColor.clearColor;
       
    }
    return  _emailtextField;
}
 

@end
